﻿<!DOCTYPE html>
<html>
<head>
    <title></title>
    <link href="/style/rightdirectory.css" rel="stylesheet" />
    <script src="/script/config.js"></script>
</head>

<body>
    <h5>发货</h5>
    <div class="form-body">
        <div class="form-horizontal  hide" id="form">

        </div>
    </div>
</body>
</html>
<script type="text/html" id="tp-form">
    <div class="form-group">
        <label class="col-sm-2">订单号</label>
        <div class="col-md-6 col-sm-10">
            <input type="text" class="form-control" readonly maxlength="50" data-form="OrderNo" placeholder="订单号" value="{{OrderNo}}">
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2">快递号</label>
        <div class="col-md-6 col-sm-10">
            <input type="text" class="form-control" maxlength="40" data-form="LogisticsNo" placeholder="快递号" value="{{LogisticsNo}}">
        </div>
    </div>



    <div id="table">

        <div class="form-group">
            <label class="col-sm-2">物流公司名称</label>
            <div class="col-md-6 col-sm-10">
                <select class="form-control enrich-drop-down" data-form="LogisticsName" value="{{LogisticsName}}">
                    <option value="">请选择类型</option>
                    {{each install item}}
                    <option value="{{item.Id}}">{{item.LogisticsName}} </option>
                    {{/each}}
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2">物流公司编号</label>
            <div class="col-md-6 col-sm-10">
                <select class="form-control enrich-drop-down" data-form="LogisticsCode" value="{{LogisticsCode}}">
                    <option value="">请选择类型</option>
                    {{each install item}}
                    <option value="{{item.Id}}" {{if item.Id==LogisticsCode}} selected {{/if}}>{{item.LogisticsCode}} </option>
                    {{/each}}
                </select>
            </div>
        </div>

    </div>
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <button type="button" id="btn-submit" class="btn btn-primary">保存</button>
            <button type="button" class="btn" onclick="window.history.go(-1)">退出</button>
        </div>
    </div>
</script>
<link href="/script/valid/css/tr.css" rel="stylesheet" /><!--判断如：PlatformName格式-->
<script src="/script/valid/form-valid.js?v=2018"></script>
<script>
    $(function () {
        $.http.json("logisticsvconfig/list", { Page: { Index: 1 } }, {
            pass: function (data) {             
                wuliu(data.Data);
            }
        })
    });

    function wuliu(d) {
        var id = QueryPageUrlString("v");
        console.log(id)
        var formValidEvent;
        var formValidInit = function () {
            var formValidData = [
                {
                    key: "LogisticsNo",
                    datatype: "*",
                    nullmsg: "不能为空哦",
                    errormsg: "不能为空哦"
                },
                {
                    key: "LogisticsCode",
                    datatype: "*",
                    nullmsg: "不能为空哦",
                    errormsg: "不能为空哦"
                },

            ];
            formValidEvent = $(".form-body").formValid(formValidData);
        }
        var inintData = {
            LogisticsNo: "",
            LogisticsCode: "",
            LogisticsName: "",
            install: d,
            OrderNo: id
        };
        console.log(inintData)
        $("#form").templateRender({ el: "tp-form", data: inintData });//渲染模板，要先渲染才能获值
        formValidInit();

        $("#form").on("click", "#btn-submit", function () { //保存按钮有添加和编辑
            if (!formValidEvent.check()) { return; }
            $.http.json("order/shipments", {
                OrderNo: id,
                LogisticsNo: "",
                LogisticsCode: "",
                LogisticsName: ""
            }, {
                    pass: function (data) {
                        $.msgSucceed("发货成功");
                    },
                    error: function (d) {
                        console.log(d);
                        $.msgFall(d.Errmsg);
                    }
                })
        });
    }
</script>
